<template>
	<view>
		<view style="background-color: #FFFFFF;">
			<cu-custom :isBack="true">
				<block slot="backText"></block>
				<block slot="content">{{corpCode}}-条码比对</block>
			</cu-custom>
		</view>
		<view class="cu-bar bg-white search fixed indexes" :style="[{top:CustomBar + 'px'}]">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input @confirm="getData" v-model="inputVal" type="text" placeholder="输入关键词" :focus="focus"></input>
			</view>
			<view class="action" @click="toScan">
				<text class="cuIcon-scan" style="font-size: 56rpx;"></text>
			</view>
		</view>
		<view class="cu-bar bg-white solid-bottom margin-top " style="margin-top: 13%;">
			<view class="action text-xl">
				<text class="cuIcon-title text-orange"></text>比对结果
			</view>
		</view>
		<scroll-view scroll-y="true" class="indexes"  :scroll-with-animation="true"
		 :enable-back-to-top="true" :style="[{height:'calc(100vh - '+ CustomBar + 'px - 100px)'}]">
			<view class="bg-white margin-bottom">
				<view>
					<view class="flex-sub text-center solid-bottom text-md padding">
						<text class="text-black text-bold">SRM结果</text>
					</view>
				</view>
				<view class="text-gray cu-form-group">
					<text class="text-blue margin-right-xs">编码：{{srmviewCode}}</text> 
				</view>
				<view class="text-gray cu-form-group">
					<text class="text-blue margin-right-xs">SKU：{{srmcinvname}}</text> 
				</view>
			</view>
			<view v-if="isShowe" class="action-section"> 
				<image src="../../static/dh.png" mode="aspectFit" style="width: 50px;height: 50px;"></image>
			</view>
			<view  v-if="isShowo" class="action-section">
				<image src="../../static/cw.png" mode="aspectFit" style="width: 50px;height: 50px;"></image>
			</view>
			<view class="bg-white margin-bottom">
				<view>
					<view class="flex-sub text-center solid-bottom text-md padding">
						<text class="text-black text-bold">海外仓结果</text>
					</view>
				</view>
				<view class="text-gray cu-form-group">
					<text class="text-blue margin-right-xs">编码：{{hwcode}}</text> 
				</view>
				<view class="text-gray cu-form-group">
					<text class="text-blue margin-right-xs">SKU：{{hwname}}</text> 
				</view>
			</view>
		</scroll-view>
		
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				focus:true,
				menuArrow:true, 
				CustomBar: this.CustomBar, //滚动定位用
				inputVal:"", //扫码值
				cdata:'',   //任务列表
				hwcode:'', //海外仓存货编码
				hwname:'', //海外仓存货名称
				srmviewCode:'',//srm存货编码
				srmcinvname:'',//srm存货名称
				posList:[],
				isCheck:false,//是否可用
				isShowe:false,
				isShowo:false,
				vals:'',
			}
		},
		computed: {
			...mapState(['hasLogin', 'userInfo', 'auditlist', 'corpCode']),
		},
		onShow() {
			
		},
		onLoad() {
			// this.inputVal = 'inv_105_1001000004_1_3';
			// this.hwcode = '1001000004';
			// this.hwname = '测试海外仓条码值';
			// inv_105_1001000001_1_2
			// this.getData();
		},
		methods: {
			//失败后继续扫描
			continueScan(){
				this.posList = [];
				this.ishow=false;
				this.srmviewCode ='';
				this.srmcinvname ='';
				this.hwname ='';
				this.hwcode ='';
			},
			/** 获取数据 扫描盘点任务单，获取当前盘点人需盘点货位列表*/
			getData(){
				// this.posList = [];
				this.cdata = '';
				this.focus = false; // 初始化 第二个输入框focus 属性
				  setTimeout(() => {
					this.focus = true; //  第二个输入框获取焦点。
				},1000)
				//1、标准条码前缀
				if((this.inputVal.indexOf("sc") > -1) || (this.inputVal.indexOf("dh") > -1) || (this.inputVal.indexOf("inv") > -1) || (this.inputVal.indexOf("po") > -1)){
					this.getPostData();
					return;
				}else{//2、客户的标签前缀（不是我们的标签就是客户的标签）
					this.getCheckPosData();
					return;
				}
			},
			
			/** 标准标签信息*/
			getPostData(){
				if(this.isCheck){
					this.cleanData();
				}
				uni.request({
					url:this.serverURL_a+'/so/App/findMapCinvcode',
					data:{
						hw : this.inputVal,
						__sid:this.userInfo.sessionid
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
					},
					method: 'POST',
					success:function(data){
						this.vals = this.inputVal;
						this.inputVal = '';
						var result = data.data;
						if(result.result == 'true'){
							var inv = result.bPos;
							if(inv.length < 1){
								this.$api.msg("SRM条码无数据!");
								this.vals = '';
								// this.scSb();
							}
							this.srmviewCode = inv.viewCode;
							this.srmcinvname = inv.cinvname;
							// this.scCg();
							this.chaeckCbarcode();
						}else{
							this.$api.msg(result.message);
							this.vals = '';
							// this.scSb();
							return;
						}
					}.bind(this),
					fail:function(){
						this.$api.msg('服务已停止,请稍后再试');
						return;
					}.bind(this),
				});
			},
			
			/** 客户方标签信息*/
			getCheckPosData(){
				if(this.isCheck){
					this.cleanData();
				}
				uni.request({
					url:this.serverURL_a+'/wh/check/api/whCheckinvTask/getSkuByCode',
					data:{
						cbarcode : this.inputVal,
						__sid:this.userInfo.sessionid
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
					},
					method: 'POST',
					success:function(data){
						this.vals = this.inputVal;
						this.inputVal = '';
						if(data.statusCode!="200"){
							if(data.statusCode == "403"){
								uni.showModal({
								    content: "权限不足!",
									showCancel:false,
								});
							}
							uni.showModal({
							    content: "其他异常!",
								showCancel:false,
							});
							return;
						}
						var result = data.data;
						if(result.result == 'true'){
							var inv = result.data;
							if(inv.length < 1){
								this.$api.msg("海外条码无数据!");
								this.vals = '';
								// this.scSb();
								return;
							}
							this.hwcode = inv.yy_id;
							this.hwname = inv.sku;
							// this.scCg();
							this.chaeckCbarcode();
						}else{
							if(result.message.indexOf("WMS") > -1){
								uni.showModal({
								    content: result.message,
									showCancel:false,
								});
							}else{
								this.$api.msg(result.message);
							}
							this.vals = '';
							// this.scSb();
							return;
						}
					}.bind(this),
					fail:function(){
						this.$api.msg('服务已停止,请稍后再试');
						return;
					}.bind(this),
				});
			},
			/** 扫码失败*/
			scSb(){
				console.log("=====testClick=====");
				let src = '../../static/smsb.mp3';
				//实例化声音  
				const Audio = uni.createInnerAudioContext();
				Audio.autoplay = true;
				Audio.src = src; //音频地址  
				Audio.play(); //执行播放  
				Audio.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});
				Audio.onPause(function() {
					console.log('end');
					Audio.destroy();
				});
			},
			/** 扫码成功*/
			scCg(){
				console.log("=====testClick=====");
				let src = '../../static/smcg.mp3';
				//实例化声音  
				const Audio = uni.createInnerAudioContext();
				Audio.autoplay = true;
				Audio.src = src; //音频地址  
				Audio.play(); //执行播放  
				Audio.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});
				Audio.onPause(function() {
					console.log('end');
					Audio.destroy();
				});
			},
			
			/** 比对条码*/
			chaeckCbarcode(){
				if(this.hwcode == '' || this.srmviewCode == '' || this.isCheck){
					return;
				}else if(this.hwcode == this.srmviewCode){
					console.log("成功")
					//提示成功声
					console.log("=====testClick=====");
					let src = '../../static/cg.mp3';
					//实例化声音  
					const Audio = uni.createInnerAudioContext();
					Audio.autoplay = true;
					Audio.src = src; //音频地址  
					Audio.play(); //执行播放  
					Audio.onError((res) => {
						console.log(res.errMsg);
						console.log(res.errCode);
					});
					Audio.onPause(function() {
						console.log('end');
						Audio.destroy();
					});
					
					this.isCheck = true;
					this.isShowe = true;
					this.isShowo = false;
				}else{
					this.ishow = true;
					console.log("失败")
					//提示失败声
					console.log("=====testClick=====");
					let src = '../../static/sb.mp3';
					//实例化声音  
					const Audio = uni.createInnerAudioContext();
					Audio.autoplay = true;
					Audio.src = src; //音频地址  
					Audio.play(); //执行播放  
					Audio.onError((res) => {
						console.log(res.errMsg);
						console.log(res.errCode);
					});
					Audio.onPause(function() {
						console.log('end');
						Audio.destroy();
					});
					// uni.showModal({
					// 	content: "比对失败！SRM存货：【"+ this.srmcinvname +"】，海外仓存货：【"+this.hwname+"】",
					// 	showCancel:false,
					// });
					this.isCheck = true;
					this.isShowe = false;
					this.isShowo = true;
				}
			},
			
			/** 清空数据 */
			cleanData(){
				this.srmviewCode ='';
				this.srmcinvname ='';
				this.hwname ='';
				this.hwcode ='';
				this.isCheck = false;
				this.isShowe = false;
				this.isShowo = false;
			},
			/** 扫码*/
			toScan(){
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						var rdata = res.result;
						this.inputVal = rdata;
						setTimeout(function(){
							this.getData();
						}.bind(this),100);
					}.bind(this)
				});
			},
		}
	}
</script>

<style>
	.confirm-btn{
		padding: 0 38upx;
		margin: 0;
		height: 76upx;
		line-height: 76upx;
		font-size: $font-base + 2upx;
		background: $uni-color-primary;
	}
	.page {
		height: 100Vh;
		width: 100vw;
	}

	.page.show {
		overflow: hidden;
	}

	.switch-sex::after {
		content: "\e716";
	}

	.switch-sex::before {
		content: "\e7a9";
	}

	.switch-music::after {
		content: "\e66a";
	}

	.switch-music::before {
		content: "\e6db";
	}
	.indexes{
		font-size: 18px;
	}
	
	/* 底部栏 */
	.action-section{
		position:fixed;
		left: 85%;
		display: flex;
		/* align-items: center; */
	}
</style>
